// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: SYZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_SYZSETUP

// Function declarations
reserve function SYZSetup_Function93
reserve function SYZSetup_Function94

// Static Values
public value SYZSetup_value29 = 0;
public value SYZSetup_value30 = 0;

// Tables

public table SYZSetup_table0
	0x300000, 0x3BD0000, 0, 100, 8, 33, 56, 1, 40, 19, 0, 22, 4, 18, 48, 1, 32, 2, 40, 39, 0, 10, 8, 7, 0, 13, 8, 11, 0, 17, 8, 14, 0, 20, 4, 15, 0, 30, 56, 1, 40, 11, 32, 29, 40, 8, 32, 39, 0, 7, 4, 27, 6, 2, 2, 32, 0, 14, 4, 45, 0, 37, 8, 8, 0, 20, 48, 1, 36, 7, 4, 49, 52, 1, 36, 18, 4, 28, 0, 20, 8, 9, 0, 19, 2, 9, 50, 1, 34, 5, 2, 7, 50, 1, 34, 4, 2, 5, 50, 1, 34, 4, 2, 33, 0, 73, 8, 69, 0, 16, 4, 45, 0, 62, 8, 19, 0, 4, 4, 39, 0, 36, 4, 9, 0, 16, 8, 7, 0, 7, 2, 17, 0, 23, 8, 18, 56, 1, 40, 41, 8, 16, 0, 32, 2, 14, 0, 2, 8, 25, 0, 11, 4, 9, 0, 44, 8, 5, 0, 14, 8, 45, 0, 52, 4, 38, 52, 1, 36, 5, 0, 13, 8, 7, 0, 21, 8, 8
end table

public table SYZSetup_table1
	0x300000, 0x3C10000, 0, 76, 8, 27, 56, 1, 40, 24, 8, 4, 0, 15, 4, 16, 52, 1, 36, 4, 32, 5, 40, 30, 8, 8, 0, 9, 8, 13, 0, 12, 8, 14, 0, 15, 8, 13, 0, 15, 4, 16, 0, 13, 8, 11, 56, 1, 40, 21, 32, 13, 36, 21, 4, 38, 2, 18, 0, 31, 4, 51, 0, 9, 8, 23, 0, 8, 52, 1, 36, 30, 4, 29, 52, 1, 36, 26, 4, 29, 0, 9, 8, 13, 0, 14, 2, 13, 50, 1, 34, 7, 2, 9, 0, 69, 8, 39, 56, 1, 40, 9, 8, 28, 0, 15, 4, 54, 0, 72, 4, 7, 48, 1, 32, 13, 0, 6, 48, 1, 32, 7, 0, 4, 48, 1, 32, 5, 0, 6, 56, 1, 40, 3, 8, 9, 56, 1, 40, 5, 8, 4, 0, 2, 48, 1, 32, 5, 0, 5, 52, 1, 36, 6, 32, 2, 0, 5, 48, 1, 32, 6, 0, 6, 48, 1, 32, 3, 36, 3, 4, 5, 48, 1, 32, 7, 0, 3, 4, 5, 48, 1, 32, 7, 0, 6, 48, 1, 32, 5, 0, 4, 8, 2, 56, 1, 40, 3, 32, 2, 0, 6, 48, 1, 32, 5, 0, 7, 48, 1, 32, 5, 0, 2, 8, 8, 56, 1, 40, 5, 8, 5, 0, 7, 4, 39, 52, 1, 36, 5, 40, 3, 8, 3, 56, 1, 40, 8, 8, 26, 48, 1, 32, 4, 36, 4, 4, 3, 0, 12, 8, 56, 0, 14, 4, 37, 0, 3, 52, 1, 36, 12, 4, 14, 0, 11, 8, 15, 56, 1, 40, 15, 8, 6, 0, 21, 4, 54, 0, 21, 8, 63, 56, 1, 40, 2, 32, 17, 0, 39
end table

public table SYZSetup_table2
	0x300000, 0x3BD0000, 0, 25, 8, 47, 56, 1, 40, 7, 0, 27, 4, 9, 0, 2, 4, 5, 52, 1, 36, 5, 40, 32, 8, 6, 0, 30, 4, 14, 0, 4, 8, 7, 0, 18, 2, 12, 50, 1, 34, 4, 0, 21, 8, 10, 56, 1, 40, 23, 8, 5, 56, 1, 40, 28, 8, 1, 0, 16, 4, 89, 0, 8, 8, 154, 56, 1, 40, 6, 8, 55, 0, 11, 4, 18, 0, 122, 8, 41, 0, 9, 8, 13, 0, 11, 4, 6, 0, 10, 4, 11, 0, 3, 2, 46, 0, 14, 8, 27, 0, 20, 4, 44, 52, 1, 36, 26, 4, 46, 52, 1, 36, 6, 0, 5, 8, 17, 0, 25, 4, 47, 0, 11, 2, 16, 0, 19, 4, 27, 0, 30, 2, 57, 0, 58, 2, 11, 0, 27, 8, 14, 0, 35, 48, 1, 32, 17, 0, 8, 8, 5, 56, 1, 40, 40, 8, 6, 0, 5, 48, 1, 32, 6, 0, 12, 8, 4, 0, 42, 8, 11, 56, 1, 40, 9, 8, 40, 56, 1, 40, 4
end table

public table SYZSetup_table3
	0x17500000, 0xBD0000, 0, 31, 8, 36, 0, 12, 8, 38, 0, 4, 2, 221, 0, 68, 2, 91, 0, 40, 48, 1, 32, 96, 0, 3, 2, 13
end table

function SYZSetup_Function93
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("SpringYard_F.ogg", 0, 0x13CE8, 0x1F40)
			break
		case 2
			SetMusicTrack("SpringYard_F.ogg", 0, 0x13CE8)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("SpringYard_F.ogg", 0, 0x13CE8)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SYZSetup_Function94
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("SpringYard.ogg", 0, 0x18BF4, 0x30D4)
			break
		case 2
			SetMusicTrack("SpringYard.ogg", 0, 0x18BF4)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("SpringYard.ogg", 0, 0x18BF4)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	object.value0++
	if object.value0 == 6
		object.value0 = 0
		object.value1++
		object.value1 &= 3
		temp0 = object.value1
		temp0++
		CopyPalette(temp0, 160, 0, 160, 32)
	end if
	object.value2++
	object.value2 %= 48
	SYZSetup_value30 = object.value2
	SYZSetup_value30 >>= 3
	SYZSetup_value29++
	SYZSetup_value29 %= 356
end event


event ObjectStartup
	SetMusicTrack("SpringYard.ogg", 0, 0x18BF4)
	SpeedUpMusic = SYZSetup_Function93
	SlowDownMusic = SYZSetup_Function94
	temp0 = 1
	temp1 = 0
	temp2 = 32
	while temp0 < 5
		LoadPalette("SYZ_PalCycle.act", temp0, 160, temp1, temp2)
		temp0++
		temp1 += 32
		temp2 += 32
	loop
	animalType1 = TypeName[Cucky]
	animalType2 = TypeName[Picky]
	object[10].type = TypeName[SYZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	SYZSetup_value29 = 0
	SYZSetup_value30 = 0
	if stage.actNum == 2
		ResetObjectEntity(211, TypeName[Blank Object], 0, 0, 0)

		arrayPos0 = 500

		temp0 = 3968
		temp0 <<= 16	
		temp1 = 1360
		temp1 <<= 16	
		ResetObjectEntity(arrayPos0, TypeName[Invisible Block], 49, temp0, temp1)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = 2
		object[arrayPos0].value1 = 4
		arrayPos0++

		temp0 = 4224
		temp0 <<= 16	
		temp1 = 1472
		temp1 <<= 16	
		ResetObjectEntity(arrayPos0, TypeName[Invisible Block], 49, temp0, temp1)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = 2
		object[arrayPos0].value1 = 4
		arrayPos0++

		temp0 = 4480
		temp0 <<= 16	
		temp1 = 1360
		temp1 <<= 16	
		ResetObjectEntity(arrayPos0, TypeName[Invisible Block], 49, temp0, temp1)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = 2
		object[arrayPos0].value1 = 4
		arrayPos0++

		temp0 = 4736
		temp0 <<= 16	
		temp1 = 1472
		temp1 <<= 16	
		ResetObjectEntity(arrayPos0, TypeName[Invisible Block], 49, temp0, temp1)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = 2
		object[arrayPos0].value1 = 4
		arrayPos0++

		temp0 = 4992
		temp0 <<= 16	
		temp1 = 1360
		temp1 <<= 16	
		ResetObjectEntity(arrayPos0, TypeName[Invisible Block], 49, temp0, temp1)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = 2
		object[arrayPos0].value1 = 4
		arrayPos0++
	end if
	
	if options.attractMode == 1
		switch stage.playerListPos
		case 0
		default
			if credits.screen == 0
				PlayerObject_ReplayTable = SYZSetup_table0
				PlayerObject_ReplaySize = 178
				PlayerObject_ReplayLength = 0x708
			else
				PlayerObject_ReplayTable = SYZSetup_table3
				PlayerObject_ReplaySize = 28
				PlayerObject_ReplayLength = 540
			end if
			break
		case 1
			if credits.screen == 0
				PlayerObject_ReplayTable = SYZSetup_table1
				PlayerObject_ReplaySize = 290
				PlayerObject_ReplayLength = 0x708
			else
				PlayerObject_ReplayTable = SYZSetup_table3
				PlayerObject_ReplaySize = 28
				PlayerObject_ReplayLength = 540
			end if
			break
		case 2
		case 5
			if credits.screen == 0
				PlayerObject_ReplayTable = SYZSetup_table2
				PlayerObject_ReplaySize = 182
				PlayerObject_ReplayLength = 0x708
			else
				PlayerObject_ReplayTable = SYZSetup_table3
				PlayerObject_ReplaySize = 28
				PlayerObject_ReplayLength = 540
			end if
			break
		end switch
		CallFunction(PlayerObject_InitReplay)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
